package Common.Entities;


import java.io.Serializable;
import java.util.LinkedList;

/**
 * This class holds the Category's entity properties and methods
 * @author Ori Ziv
 *
 */
public class Category extends CatalogItem implements Serializable{

	// Class private members
	private static final long serialVersionUID = -6134814223992674143L;
	private LinkedList<Type>types;

	//////////////////////////////////////////////////////////////////////
	
	// Class constructors
	/**
	 * @param itmID - product category ID
	 * @param itmName - product category name
	 */
	public Category(String itmID, String itmName) {
		super(itmID, itmName);
		types = new LinkedList<Type>();
	}

	/**
	 * @param itmID - product category ID
	 * @param itmName - product category name
	 * @param itmDescription - product category description
	 */
	public Category(String itmID, String itmName, String itmDescription) {
		super(itmID, itmName, itmDescription);
		types = new LinkedList<Type>();
	}
	
	///////////////////////////////////////////////////////////////////////
	
	// Class public methods
	
	/**
	 * This method sets the relation between a Category object and a Type object
	 * @param type - type object to relate
	 */
	public void reltaeTypeCategory(Type type) {
		types.add(type);
	}
	
	/**
	 * This method check rather a Category object is related to a specific type object
	 * @param typeID - Type object's ID
	 * @return - true if relation exists otherwise return false
	 */
	public boolean isTypeRelated(String typeID) {
		for (Type t : types)
			if (t.getItmID().equals(typeID))
				return true;
		return false;
	}
	
	/**
	 * This method return the number of types related to a Category object (might be 0 to infinity) 
	 * @return - int representing the number of type relations
	 */
	public int getNumOfTypes() {
		return types.size();
	}
	
	/**
	 * This method removes a relation between this Category object to a specific type.
	 * @param typeID - Type ID to be removed
	 */
	public void unrelateType(String typeID) {
		for (Type t : types)
			if (t.getItmID().equals(typeID))
				types.remove(types.indexOf(t));
	}

}
